// http://patorjk.com/software/taag/#p=display&h=1&f=Small%20Slant&t=TIMELINE
console.log(` ______ ____ __  ___ ____ __    ____ _  __ ____
/_  __//  _//  |/  // __// /   /  _// |/ // __/
 / /  _/ / / /|_/ // _/ / /__ _/ / /    // _/  
/_/  /___//_/  /_//___//____//___//_/|_//___/  

LOOK FORWARD TO WORKING WITH YOU...

`);
console.group("timeline.ink");
console.log("Get Windows app: https://www.microsoft.com/store/apps/9N7VHQ989BB7");
console.log("Any questions, please contact me: nguaduot@163.com");
console.log(`Learn more: ${window.location.origin}/about`);
console.groupEnd();

$(document).ready(function() {
  if (!$.cookie("browser") || !$.cookie("os") || !$.cookie("screen") || !$.cookie("region")) {
    let info_browser = navigator?.userAgentData?.brands[0]["brand"] || "unknown";
    let info_os = navigator?.userAgentData?.platform || navigator?.platform || "unknown";
    let info_screen = (window.screen.width * window.devicePixelRatio).toFixed()
      + "x" + (window.screen.height * window.devicePixelRatio).toFixed()
      + "," + window.devicePixelRatio.toFixed(2);
    let info_region = Intl.DateTimeFormat().resolvedOptions().timeZone || "unknown";
    let cookie_option = {
      expires: 31,
      path: "/"
    }; // 一个月有效
    $.cookie("browser", info_browser, cookie_option);
    $.cookie("os", info_os, cookie_option);
    $.cookie("screen", info_screen, cookie_option);
    $.cookie("region", info_region, cookie_option);
  }
  // 缓存浏览器指纹（浏览器更新可能导致指纹变化，设置长期有效）
  if (!$.cookie("fingerprint")) {
    FP_PROMISE.then(fp => fp.get()).then(result => {
      $.cookie("fingerprint", result.visitorId, { // 顶级域名共享
        domain: getDomain(),
        path: "/",
        expires: 365
      });
    });
  }
});

function getDomain() {
  if (["localhost", "127.0.0.1"].indexOf(location.hostname) >= 0) {
    return location.hostname;
  }
  return location.hostname.split(".").slice(-2).join(".");
}